<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="payUuid">
      <el-input v-model="dataForm.payUuid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payName">
      <el-input v-model="dataForm.payName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payAddress">
      <el-input v-model="dataForm.payAddress" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payPhone">
      <el-input v-model="dataForm.payPhone" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payPrice">
      <el-input v-model="dataForm.payPrice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="isPay">
      <el-input v-model="dataForm.isPay" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="sendTime">
      <el-input v-model="dataForm.sendTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payCount">
      <el-input v-model="dataForm.payCount" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="proId">
      <el-input v-model="dataForm.proId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payShow">
      <el-input v-model="dataForm.payShow" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="isRefund">
      <el-input v-model="dataForm.isRefund" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="status">
      <el-input v-model="dataForm.status" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="refundStatus">
      <el-input v-model="dataForm.refundStatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="shoppingStatus">
      <el-input v-model="dataForm.shoppingStatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="scheduledTime">
      <el-input v-model="dataForm.scheduledTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payTime">
      <el-input v-model="dataForm.payTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="city">
      <el-input v-model="dataForm.city" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="province">
      <el-input v-model="dataForm.province" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="subOrderUuid">
      <el-input v-model="dataForm.subOrderUuid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="userId">
      <el-input v-model="dataForm.userId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="addressId">
      <el-input v-model="dataForm.addressId" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          payUuid: '',
          payName: '',
          payAddress: '',
          payPhone: '',
          payPrice: '',
          isPay: '',
          createTime: '',
          sendTime: '',
          payCount: '',
          updateTime: '',
          proId: '',
          payShow: '',
          isRefund: '',
          status: '',
          refundStatus: '',
          shoppingStatus: '',
          scheduledTime: '',
          payTime: '',
          city: '',
          province: '',
          subOrderUuid: '',
          userId: '',
          addressId: ''
        },
        dataRule: {
          payUuid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payAddress: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payPhone: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isPay: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          sendTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payCount: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          proId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payShow: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          isRefund: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          refundStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          shoppingStatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          scheduledTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          subOrderUuid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          addressId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/school/orderinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.payUuid = data.orderInfo.payUuid
                this.dataForm.payName = data.orderInfo.payName
                this.dataForm.payAddress = data.orderInfo.payAddress
                this.dataForm.payPhone = data.orderInfo.payPhone
                this.dataForm.payPrice = data.orderInfo.payPrice
                this.dataForm.isPay = data.orderInfo.isPay
                this.dataForm.createTime = data.orderInfo.createTime
                this.dataForm.sendTime = data.orderInfo.sendTime
                this.dataForm.payCount = data.orderInfo.payCount
                this.dataForm.updateTime = data.orderInfo.updateTime
                this.dataForm.proId = data.orderInfo.proId
                this.dataForm.payShow = data.orderInfo.payShow
                this.dataForm.isRefund = data.orderInfo.isRefund
                this.dataForm.status = data.orderInfo.status
                this.dataForm.refundStatus = data.orderInfo.refundStatus
                this.dataForm.shoppingStatus = data.orderInfo.shoppingStatus
                this.dataForm.scheduledTime = data.orderInfo.scheduledTime
                this.dataForm.payTime = data.orderInfo.payTime
                this.dataForm.city = data.orderInfo.city
                this.dataForm.province = data.orderInfo.province
                this.dataForm.subOrderUuid = data.orderInfo.subOrderUuid
                this.dataForm.userId = data.orderInfo.userId
                this.dataForm.addressId = data.orderInfo.addressId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/school/orderinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'payUuid': this.dataForm.payUuid,
                'payName': this.dataForm.payName,
                'payAddress': this.dataForm.payAddress,
                'payPhone': this.dataForm.payPhone,
                'payPrice': this.dataForm.payPrice,
                'isPay': this.dataForm.isPay,
                'createTime': this.dataForm.createTime,
                'sendTime': this.dataForm.sendTime,
                'payCount': this.dataForm.payCount,
                'updateTime': this.dataForm.updateTime,
                'proId': this.dataForm.proId,
                'payShow': this.dataForm.payShow,
                'isRefund': this.dataForm.isRefund,
                'status': this.dataForm.status,
                'refundStatus': this.dataForm.refundStatus,
                'shoppingStatus': this.dataForm.shoppingStatus,
                'scheduledTime': this.dataForm.scheduledTime,
                'payTime': this.dataForm.payTime,
                'city': this.dataForm.city,
                'province': this.dataForm.province,
                'subOrderUuid': this.dataForm.subOrderUuid,
                'userId': this.dataForm.userId,
                'addressId': this.dataForm.addressId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
